package com.superzqb.asus.superzqbFragment.superzqbJobShop.Home;


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.baoyz.widget.PullRefreshLayout;
import com.superzqb.asus.superzqb.R;
import com.superzqb.asus.superzqbFragment.superzqbJobShop.Adapter.CampusShopLogisticsAdapter;
import com.superzqb.asus.superzqbFragment.superzqbJobShop.Bean.CampusShopAllBean;
import com.superzqb.asus.superzqbFragment.superzqbSave.Adapter.SaveAdapter;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * A simple {@link Fragment} subclass.
 */
public class CampusLogisticsSubFragment extends Fragment {
    private Context context;
    private ListView listView;
    private PullRefreshLayout layout;
    private ArrayList<Map<String, Object>> listAll= new ArrayList<>();
    private CampusShopLogisticsAdapter adapter;
    public static ArrayList<Map<String, Object>> list = new ArrayList<>();
    private int type;

    public CampusLogisticsSubFragment() {
        // Required empty public constructor
    }
    public void getLv() {
        list.clear();
        for(int i=0;i<5;i++) {
            Map<String, Object> map = new HashMap<>();
            //键一般为"字符串"
            map.put("orderNum", "418w143242342340"+i+type);
            map.put("name", "user"+i+type);
            map.put("orderLog", "8ssad0"+i+type);
            map.put("orderGoods", "测试商品"+i+type);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
            map.put("orderTime", dateFormat.format(new Date()));
            list.add(map);
        }
        listAll.addAll(list);
        adapter.setList(listAll);
        adapter.notifyDataSetChanged();

    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);


        adapter=new CampusShopLogisticsAdapter(context,list);

        listView.setAdapter(adapter);

    }

    private void initView(View view) {
        layout= (PullRefreshLayout) view.findViewById(R.id.swipeRefreshLayout);
        listView=(ListView)view.findViewById(R.id.listView);
        context=getActivity();
        type=getArguments().getInt("type");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.campus_logistics_sub, container, false);
    }

    @Override
    public void onResume() {
        super.onResume();
        getLv();
    }
}
